{% extends "base.html" %}

{% block content %}
<style>
    .login-container {
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 100vh;
        background: linear-gradient(135deg, #1e5799 0%, #207cca 51%, #2989d8 100%);
        background-size: 400% 400%;
        animation: gradientBG 15s ease infinite;
        padding: 20px;
    }

    @keyframes gradientBG {
        0% {
            background-position: 0% 50%;
        }

        50% {
            background-position: 100% 50%;
        }

        100% {
            background-position: 0% 50%;
        }
    }

    .login-box {
        width: 100%;
        max-width: 420px;
        padding: 40px;
        background: rgba(255, 255, 255, 0.95);
        border-radius: 12px;
        box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
        position: relative;
        overflow: hidden;
        transform: translateY(0);
        transition: transform 0.3s ease, box-shadow 0.3s ease;
    }

    .login-box:hover {
        transform: translateY(-5px);
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
    }

    .login-box::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 5px;
        background: linear-gradient(90deg, #1E9FFF, #0077e6);
    }

    .login-title {
        text-align: center;
        margin-bottom: 30px;
        color: #2c3e50;
        font-size: 28px;
        font-weight: 600;
        position: relative;
    }

    .login-title::after {
        content: '';
        display: block;
        width: 60px;
        height: 3px;
        background: #1E9FFF;
        margin: 10px auto;
        border-radius: 2px;
    }

    .login-icon {
        display: flex;
        justify-content: center;
        margin-bottom: 25px;
    }

    .login-icon i {
        font-size: 48px;
        color: #1E9FFF;
        background: rgba(30, 159, 255, 0.1);
        width: 80px;
        height: 80px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 2px solid rgba(30, 159, 255, 0.2);
    }

    .layui-form-item {
        margin-bottom: 25px;
    }

    .layui-form-label {
        width: auto;
        padding-left: 0;
        color: #555;
        font-weight: 500;
    }

    .layui-input-block {
        margin-left: 0;
    }

    .layui-input {
        height: 48px;
        border-radius: 8px;
        border: 1px solid #e0e0e0;
        padding-left: 15px;
        font-size: 16px;
        transition: all 0.3s;
    }

    .layui-input:focus {
        border-color: #1E9FFF;
        box-shadow: 0 0 0 3px rgba(30, 159, 255, 0.15);
    }

    .login-btn {
        height: 50px;
        line-height: 50px;
        font-size: 18px;
        font-weight: 500;
        border-radius: 8px;
        background: linear-gradient(90deg, #1E9FFF, #0077e6);
        border: none;
        box-shadow: 0 4px 10px rgba(30, 159, 255, 0.3);
        transition: all 0.3s;
    }

    .login-btn:hover {
        transform: translateY(-3px);
        box-shadow: 0 7px 15px rgba(30, 159, 255, 0.4);
    }

    .login-options {
        display: flex;
        justify-content: space-between;
        margin-top: 15px;
        font-size: 14px;
    }

    .login-options a {
        color: #1E9FFF;
        text-decoration: none;
        transition: color 0.2s;
    }

    .login-options a:hover {
        color: #0077e6;
        text-decoration: underline;
    }

    .error-message {
        background: #ffeded;
        color: #ff4d4f;
        padding: 12px 15px;
        border-radius: 8px;
        border: 1px solid #ffd1d1;
        margin-bottom: 20px;
        display: flex;
        align-items: center;
    }

    .error-message i {
        margin-right: 8px;
        font-size: 18px;
    }

    .footer-text {
        text-align: center;
        margin-top: 25px;
        color: #7f8c8d;
        font-size: 14px;
    }

    /* 响应式调整 */
    @media (max-width: 480px) {
        .login-box {
            padding: 30px 20px;
        }

        .login-title {
            font-size: 24px;
        }

        .layui-form-item {
            margin-bottom: 20px;
        }

        .layui-input {
            height: 44px;
        }

        .login-btn {
            height: 46px;
            line-height: 46px;
            font-size: 16px;
        }
    }
</style>

<div class="login-container">
    <div class="login-box">
        <div class="login-icon">
            <i class="layui-icon layui-icon-username"></i>
        </div>

        <h2 class="login-title">网络工具箱</h2>
        {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
        {% for category, message in messages %}
        <div class="error-message">
            <i class="layui-icon layui-icon-face-cry"></i>
            {{ message }}
        </div>
        {% endfor %}
        {% endif %}
        {% endwith %}


        <form class="layui-form" method="POST" action="{{ url_for('auth.login') }}">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="username" required lay-verify="required" placeholder="请输入用户名"
                        autocomplete="username" class="layui-input"
                        value="{{ request.form.username if request.form.username else '' }}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" required lay-verify="required" placeholder="请输入密码"
                        autocomplete="current-password" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn login-btn layui-btn-fluid" lay-submit lay-filter="formLogin">登录系统</button>
                </div>
            </div>

            <div class="login-options">
                <a href="javascript:void(0);" onclick="showForgotPassword()">
                    <i class="layui-icon layui-icon-help"></i> 忘记密码?
                </a>
                <a href="javascript:void(0);" onclick="showRegister()">
                    <i class="layui-icon layui-icon-user"></i> 注册账号
                </a>
            </div>
        </form>

        <div class="footer-text">
            <p>© 2023 网络工具箱 | 安全登录系统</p>
        </div>
    </div>
</div>

<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        var layer = layui.layer;

        form.render();

        // 添加表单提交动画
        form.on('submit(formLogin)', function (data) {
            // 显示加载动画
            layer.msg('正在登录，请稍候...', {
                icon: 16,
                time: 3000,
                shade: 0.3
            });
            return true;
        });
    });

    function showForgotPassword() {
        layer.msg('请联系系统管理员重置密码', {
            icon: 0,
            time: 3000,
            shade: 0.3
        });
    }

    function showRegister() {
        layer.msg('请联系系统管理员开通账号', {
            icon: 0,
            time: 3000,
            shade: 0.3
        });
    }
</script>
{% endblock %}